home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Deutsche Edition 1
/
Deutsche Edition 1.iso
/
amok
/
amok_lha
/
amok29.lha
/
Strings
/
StringOpsTest.mod
< prev
next >
Wrap
Text File
|
1993-08-15
|
13KB
|
442 lines
(**********************************************************************
:Program. StringOpsTest.mod
:Contents. Test module for StringOps
:Author. Nicolas Benezan [bne]
:Address. Postwiesenstr. 2, D7000 Stuttgart 60
:Phone. 711/333679
:Copyright. Public Domain
:Language. Modula-2
:Translator. M2Amiga A+L V3.2d
:Imports. StringOps [bne]
:History. V1.0a [bne] 17.May.1989
**********************************************************************)
MODULE StringOpsTest;
FROM Arts IMPORT BreakPoint;
FROM InOut IMPORT Write, WriteInt, WriteLn, WriteString;
FROM StringOps IMPORT Append, AppendChar, Assign, CapChar, CapString,
Compare, Concat, DeleteSubString, FindChar,
FindSubString, InsertChar, InsertSubString, Length,
OverWrite, SubString;
FROM SYSTEM IMPORT ADR;
VAR
s8,t8:ARRAY [0..7] OF CHAR;
s12,t12:ARRAY [0..11] OF CHAR;
s6,t6:ARRAY [0..5] OF CHAR;
s4,t4:ARRAY [0..3] OF CHAR;
c,d:CHAR;
n:INTEGER;
PROCEDURE Result(Str:ARRAY OF CHAR);
BEGIN
WriteString(" = ");
WriteString(Str);
WriteLn;
END Result;
PROCEDURE Print(Text:ARRAY OF CHAR);
BEGIN
WriteString(Text);
END Print;
PROCEDURE Number(n:INTEGER);
BEGIN
WriteString(": ");
WriteInt(n,1);
WriteLn;
END Number;
BEGIN
(**)
(* Append *)
(**)
BreakPoint(ADR("Testing Append"));
Print("'text' + 'test' into s8");
s8:="text";
Append(s8,"test");
Result(s8);
Print("'text' + 'test' into s11");
s12:="text";
Append(s12,"test");
Result(s12);
Print("'text' + 'test' into s4");
s4:="text";
Append(s4,"test");
Result(s4);
Print("'text' + 'test' into s6");
s6:="text";
Append(s6,"test");
Result(s6);
Print("'text' + '' into s8");
s8:="text";
Append(s8,"");
Result(s8);
Print("'' + 'text' into s8");
s8:="";
Append(s8,"text");
Result(s8);
WriteLn;
(**)
(* AppendChar *)
(**)
BreakPoint(ADR("Testing AppendChar"));
Print("'text' + 'x' into s8");
s8:="text";
AppendChar(s8,"x");
Result(s8);
Print("'texts' + 'x' into s6");
s6:="texts";
AppendChar(s6,"x");
Result(s6);
Print("'text' + 'x' into s4");
s4:="text";
AppendChar(s4,"x");
Result(s4);
Print("'' + 'x' into s8");
s8:="";
AppendChar(s8,"x");
Result(s8);
WriteLn;
(**)
(* Assign *)
(**)
BreakPoint(ADR("Testing Assign"));
Print("'test' s4 to s4");
s4:="test";
Assign(s4,t4);
Result(t4);
Print("'test' s6 to s4");
s6:="test";
Assign(s6,t4);
Result(t4);
Print("'test' s4 to s6");
s4:="test";
Assign(s4,t6);
Result(t6);
Print("'testtext' s8 to s4");
s8:="testtext";
Assign(s8,t4);
Result(t4);
WriteLn;
(**)
(* CapChar *)
(**)
BreakPoint(ADR("Testing CapChar"));
FOR c:=CHR(32) TO CHR(127) DO
Write(c);
END;
WriteLn;
FOR c:=CHR(32) TO CHR(127) DO
d:=c;
CapChar(d);
Write(d);
END;
WriteLn;
FOR c:=CHR(160) TO CHR(255) DO
Write(c);
END;
WriteLn;
FOR c:=CHR(160) TO CHR(255) DO
d:=c;
CapChar(d);
Write(d);
END;
WriteLn;
WriteLn;
(**)
(* CapString *)
(**)
BreakPoint(ADR("Testing CapString"));
Print("Grüße s6");
s6:="Grüße";
CapString(s6);
Result(s6);
Print("Grmf s4");
s4:="Grmf";
CapString(s4);
Result(s4);
WriteLn;
(**)
(* FindChar *)
(**)
BreakPoint(ADR("Testing FindChar"));
Print("find 's' in 'teststring' s12");
s12:="teststring";
Number(FindChar(s12,"s",0));
Print("backward");
Number(FindChar(s12,"s",-9));
Print("from position 3 (t)");
Number(FindChar(s12,"s",3));
Print("backward");
Number(FindChar(s12,"s",-3));
Print("from position 4 (s)");
Number(FindChar(s12,"s",4));
Print("backward");
Number(FindChar(s12,"s",-4));
Print("find 'x' in 'testtext' s8");
s8:="testtext";
Number(FindChar(s8,"x",0));
Print("backward");
Number(FindChar(s8,"x",-7));
Print("find 'x' in 'teststring' s12");
Number(FindChar(s12,"x",0));
Print("backward");
Number(FindChar(s12,"x",-9));
Print("find 'i' in 'testtext' s8");
Number(FindChar(s8,"i",0));
Print("backward");
Number(FindChar(s8,"i",-7));
Print("find 'x' in '' s4");
s4:="";
Number(FindChar(s4,"x",0));
WriteLn;
(**)
(* Compare *)
(**)
BreakPoint(ADR("Testing Compare"));
Print("'test' s4 vs 'test' s4");
s4:="test";
t4:="test";
Number(Compare(s4,t4));
Print("'test' s8 vs 'test' s8");
s8:="test";
t8:="test";
Number(Compare(s8,t8));
Print("'test' s4 vs 'test' s8");
Number(Compare(s4,s8));
Print("'test' s4 vs 'text' s4");
s4:="test";
t4:="text";
Number(Compare(s4,t4));
Print("'text' s4 vs 'test' s4");
Number(Compare(t4,s4));
Print("'test' s4 vs 'teststring' s12");
s12:="teststring";
Number(Compare(s4,s12));
Print("'test' s4 vs '' s4");
t4:="";
Number(Compare(s4,t4));
WriteLn;
(**)
(* DeleteSubString *)
(**)
BreakPoint(ADR("Testing DeleteSubString"));
Print("remove 'test' (0,4) from 'teststring' s12");
s12:="teststring";
DeleteSubString(s12,0,4);
Result(s12);
Print("remove 'st' (4,2) from 'teststring' s12");
s12:="teststring";
DeleteSubString(s12,4,2);
Result(s12);
Print("remove 'ing' (7,3) from 'teststring' s12");
s12:="teststring";
DeleteSubString(s12,7,3);
Result(s12);
Print("deleting whole (0,9) 'teststring' s12");
s12:="teststring";
DeleteSubString(s12,0,9);
Result(s12);
Print("remove 'test' (0,4) from 'testtext' s8");
s8:="testtext";
DeleteSubString(s8,0,4);
Result(s8);
Print("remove 't' (4,1) from 'testtext' s8");
s8:="testtext";
DeleteSubString(s8,4,1);
Result(s8);
Print("remove 'text' (4,4) from 'testtext' s8");
s8:="testtext";
DeleteSubString(s8,4,4);
Result(s8);
Print("deleting whole (0,8) 'testtext' s8");
s8:="testtext";
DeleteSubString(s8,0,8);
Result(s8);
Print("deleting over end (4,7) of 'teststring' s12");
s12:="teststring";
DeleteSubString(s12,4,7);
Result(s12);
Print("deleting over end (4,5) of 'testtext' s8");
s8:="testtext";
DeleteSubString(s8,4,5);
Result(s8);
Print("deleting nothing (2,0) out of 'teststring' s12");
s12:="teststring";
DeleteSubString(s12,2,0);
Result(s12);
WriteLn;
(**)
(* FindSubString *)
(**)
BreakPoint(ADR("Testing FindSubString"));
Print("find 'str' s4 in 'teststring' s12");
s4:="str";
s12:="teststring";
Number(FindSubString(s12,s4,0));
Print("from position 3 (t)");
Number(FindSubString(s12,s4,3));
Print("from position 4 (s)");
Number(FindSubString(s12,s4,4));
Print("from position 5 (s)");
Number(FindSubString(s12,s4,5));
Print("find 'ttex' s4 in 'testtext' s8");
s4:="ttex";
s8:="testtext";
Number(FindSubString(s8,s4,0));
Print("from position 6 (e)");
Number(FindSubString(s8,s4,6));
Print("find 'tx' in 'teststring' s12");
Number(FindSubString(s12,"tx",0));
Print("find 'in' in 'testtext' s8");
Number(FindSubString(s8,"in",0));
Print("find '' in 'test' s4");
s4:="test";
Number(FindSubString(s4,"",0));
Print("find 'xx' in '' s4");
s4:="";
Number(FindSubString(s4,"xx",0));
WriteLn;
(**)
(* InsertSubString *)
(**)
BreakPoint(ADR("Testing InsertSubString"));
Print("inserting 'test' into 'text' s8 at pos 0");
s8:="text";
InsertSubString(s8,"test",0);
Result(s8);
Print("inserting 'xx' into 'text' s8 at pos 2");
s8:="text";
InsertSubString(s8,"xx",2);
Result(s8);
Print("inserting 'test' into 'text' s8 at pos 4");
s8:="text";
InsertSubString(s8,"test",4);
Result(s8);
Print("inserting 'test' into '' s8 at pos 0");
s8:="";
InsertSubString(s8,"test",0);
Result(s8);
Print("inserting '' into 'text' s8 at pos 1");
s8:="text";
InsertSubString(s8,"",1);
Result(s8);
Print("inserting 'test' s4 into 'text' s6 at pos 2");
s4:="test";
s6:="text";
InsertSubString(s6,s4,2);
Result(s6);
WriteLn;
(**)
(* InsertChar *)
(**)
BreakPoint(ADR("Testing InsertChar"));
Print("inserting 'x' into 'text' s8 at pos 0");
s8:="text";
InsertChar(s8,"x",0);
Result(s8);
Print("inserting 'y' into 'text' s8 at pos 3");
s8:="text";
InsertChar(s8,"y",3);
Result(s8);
Print("inserting 'x' into 'text' s8 at pos 4");
s8:="text";
InsertChar(s8,"x",4);
Result(s8);
Print("inserting 'x' into '' s8 at pos 0");
s8:="";
InsertChar(s8,"x",0);
Result(s8);
Print("inserting 'x' into 'texttest' s8 at pos 1");
s8:="texttest";
InsertChar(s8,"x",1);
Result(s8);
Print("inserting 's' into 'text' s4 at pos 2");
s4:="text";
InsertChar(s4,"s",2);
Result(s4);
WriteLn;
(**)
(* Length *)
(**)
BreakPoint(ADR("Testing Length"));
Print("length of 'teststring' s12");
s12:="teststring";
Number(Length(s12));
Print("length of 'testtext' s8");
s8:="testtext";
Number(Length(s8));
Print("length of '' s4");
s4:="";
Number(Length(s4));
WriteLn;
(**)
(* OverWrite *)
(**)
BreakPoint(ADR("Testing OverWrite"));
Print("overwriting 'teststring' s12 with 'xyz' at pos 0");
s12:="teststring";
OverWrite(s12,"xyz",0);
Result(s12);
Print("overwriting 'teststring' s12 with 'xyz' at pos 4");
s12:="teststring";
OverWrite(s12,"xyz",4);
Result(s12);
Print("overwriting 'teststring' s12 with 'xyz' at pos 7");
s12:="teststring";
OverWrite(s12,"xyz",7);
Result(s12);
Print("overwriting 'teststring' s12 with 'xyz' at pos 9");
s12:="teststring";
OverWrite(s12,"xyz",9);
Result(s12);
Print("overwriting 'teststring' s12 with 'text' s4 at pos 4");
s12:="teststring";
s4:="text";
OverWrite(s12,s4,4);
Result(s12);
Print("overwriting 'testtext' s8 with 'string' at pos 4");
s8:="testtext";
OverWrite(s8,"string",4);
Result(s8);
WriteLn;
(**)
(* SubString *)
(**)
BreakPoint(ADR("Testing SubString"));
Print("slices ([0..10],3) of 'teststring' s12");
s12:="teststring";
WriteLn;
FOR n:=0 TO 10 DO
SubString(s12,s4,n,3);
Print(s4);
WriteLn;
END;
Print("slice (6,3) of 'testtext' s8");
s8:="testtext";
SubString(s8,s4,6,3);
Result(s4);
Print("slice (6,0) of 'testtext' s8");
SubString(s8,s4,6,0);
Result(s4);
END StringOpsTest.